package com.code.wanmi.controller;


import com.alibaba.fastjson.JSON;
import com.code.wanmi.entity.other.ResponseBean;
import com.code.wanmi.entity.wm_user.UserDto;
import com.code.wanmi.entity.wm_user.WmSysMenu;
import com.code.wanmi.entity.wm_user.WmSysRole;
import com.code.wanmi.service.IWmSysRoleService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 角色信息表 前端控制器
 * </p>
 *
 * @author 谢晓峰
 * @since 2019-12-05
 */
@RestController
@RequestMapping("/role")
@Api()
public class WmSysRoleController {
    @Autowired
    private IWmSysRoleService iWmSysRoleService;

//    /**添加角色*/
//    @RequestMapping(value = "/add",method = RequestMethod.POST)
//    public  String addRole(@RequestBody WmSysRole wmSysRole) {
//        iWmSysRoleService.addRole(wmSysRole);
//        return JSON.toJSONString(new ResponseBean(200,"success"));
//    }

    //    添加角色与权限
    @PostMapping("/addRoleMenu")
    public String addRoleMenu(@RequestBody UserDto userDto){

        int i=iWmSysRoleService.addUserMenu(userDto);
        return i>0?JSON.toJSONString(new ResponseBean(200,"success"))
                :JSON.toJSONString(new ResponseBean(40,"fail"));
    }

    //修改角色菜单权限
//    @PostMapping("/updateRoleMenu")
//    public String updateRoleMenu(@RequestBody UserDto userDto){
//        int i=iWmSysRoleService.updateMenu(userDto);
//        if(i>0){
//            return "200";
//        }else{
//            return "500";
//        }
//    }
    /**
     * 角色显示
     */
    @RequestMapping(value = "/dispaly",method = RequestMethod.GET)
    public String daiplay(){
        return JSON.toJSONString(new ResponseBean(200,"SUCCESS",iWmSysRoleService.display()));
    }


    /**
     * 根据角色ID删除角色
     * @return
     */
    @RequestMapping(value = "/deleteRole",method = RequestMethod.PATCH)
    String deleteRoleById(@RequestParam("roleId") Long roleId) {
        int power= iWmSysRoleService.deleteRoleById(roleId);
        return power>0?JSON.toJSONString(new ResponseBean(200,"SUCCESS")):
                JSON.toJSONString(new ResponseBean(401,"FAIL"));
    }


}
